package com.doudou.provider;

import com.google.gson.Gson;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Author: 傻男人
 * @Date: 2020/6/2 16:32
 * @Version: 1.0
 * @Description:
 */
public class SecurityContextUtils{

    public static String getLoginAccount(){
        return SecurityContextHolder.getContext().getAuthentication().getName();
    }

    public static String getToken(){
        return getAuthenticationInfo().getTokenValue();
    }

    public static AuthenticationInfo getAuthenticationInfo(){
        Gson gson = new Gson();
        return gson.fromJson(gson.toJson(SecurityContextHolder.getContext().getAuthentication().getDetails()),AuthenticationInfo.class);
    }

}
